package org.pewpew.model;

import com.google.gson.Gson;

public class Player {

	private double longitude;
	private double latitude;
	private double orientation;

	private double health = 100;
	private boolean dead = false;
	private String username;

	public Player() {
	}

	public Player(String username, double longitude, double latitude, double orientation) {
		this.username = username;
		this.latitude = latitude;
		this.longitude = longitude;
		this.orientation = orientation;
	}

	@Override
	public String toString() {
		return toJSON();
	}

	public String toJSON() {
		//return new JSONSerializer().serialize(this);
		return new Gson().toJson(this);
	}
	
	public static Player fromJSON(String jsonString) {
		//return new JSONDeserializer <Player>().deserialize( jsonString );
		return new Gson().fromJson(jsonString, Player.class);
	}
	
	
	////@JSON
	public void setLongitude(double longitude) {
		this.longitude = longitude;
	}

	////@JSON
	public double getLongitude() {
		return longitude;
	}

	//@JSON
	public void setLatitude(double latitude) {
		this.latitude = latitude;
	}

	//@JSON
	public double getLatitude() {
		return latitude;
	}

	//@JSON
	public void setOrientation(double orientation) {
		this.orientation = orientation;
	}

	//@JSON
	public double getOrientation() {
		return orientation;
	}

	//@JSON
	public void setHealth(double health) {
		this.health = health;
	}

	//@JSON
	public double getHealth() {
		return health;
	}

	//@JSON
	public void setDead(boolean dead) {
		this.dead = dead;
	}

	//@JSON
	public boolean getDead() {
		return dead;
	}

	//@JSON
	public void setUsername(String name) {
		this.username = name;
	}

	//@JSON
	public String getUsername() {
		return username;
	}

	public Player getMovedCopy(double lo, double la) {
		return new Player(getUsername(), getLongitude() + lo, getLatitude() + la, getOrientation());
	}

	public Player getCopy() {
		return getMovedCopy(0, 0);
	}

}
